/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.plugins.impl;

import java.util.List;

import org.grayrabbit.cms.dao.plugins.VoteOptionDao;
import org.grayrabbit.cms.entity.VoteOption;
import org.grayrabbit.cms.service.plugins.VoteOptionService;
import org.grayrabbit.cms.vo.plugins.VoteOptionBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：





 * @version 1.0,创建时间: 2011-05-16 16:08:31  
 */
@Service
@Transactional
public class VoteOptionServiceImpl extends GenericServiceImpl implements VoteOptionService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("voteOptionDaoImpl")
	private VoteOptionDao voteOptionDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see VoteOptionService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public VoteOption getVoteOption(final String voteOptionId){
		VoteOption voteOption = voteOptionDao.findById(voteOptionId);
		voteOptionDao.initialize(voteOption);
		return voteOption;
	}
	
	/**
	 * @see VoteOptionService#delete(String)
	 */
	@Transactional
	public void delete(final VoteOption voteOption) {
		voteOptionDao.makeTransient(voteOption);
	}
	
	/**
	 * @see VoteOptionService#save(OperLog)
	 */
	@Transactional
	public void save(final VoteOption voteOption) {
		voteOptionDao.makePersistent(voteOption);		
	}
	
	/**
	 * 此方法执行时为只读事务：
	 * @see VoteOptionService#getPage(VoteOptionBean)
	 */
	@Transactional(readOnly=true)
	public Page<VoteOption> getPage(final VoteOptionBean voteOptionBean){
		Page<VoteOption> page =  new Page<VoteOption>();
		page.setTotal(voteOptionDao.count(voteOptionBean));
		page.setResult(voteOptionDao.findByQc(voteOptionDao.assembly(voteOptionBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see VoteOptionService#list(Page, VoteOptionBean)
	 */
	public void list(Page<VoteOption> page, VoteOptionBean voteOptionBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(voteOptionDao.count(voteOptionBean));
		}
		page.setResult(voteOptionDao.findByPage(page,voteOptionBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see VoteOptionService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			voteOptionDao.makeTransient(voteOptionDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				voteOptionDao.clear();
		}
		
	}
	/**
	 * 根据voteId查询voteOption列表
	 * @param voteId
	 * @return
	 */
	public List<VoteOption> findByVoteId(String voteId){
		
		return voteOptionDao.findByVoteId(voteId);
	}
}